﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RaiderManagerBackend
{
    public class PlayerPerformanceEntry
    {
        private int _dps;
        private int _medianDPS;
        private double _difference = 0;
        private Player _player = null;
        private Raid _raid = null;
        private Encounter _boss = null;
        private int _performanceEntryId;

        public PlayerPerformanceEntry(Raid raid, Encounter boss, Player player)
        {
            Raid = raid;
            Boss = boss;
            Player = player;
        }

        public PlayerPerformanceEntry(Raid raid, Player player, Encounter boss, int dps, int medianDPS)
        {
            Raid = raid;
            Player = player;
            Boss = boss;
            DPS = dps;
            MedianDPSForSpecAndEncounter = medianDPS;
        }

        #region Properties

        public Raid Raid
        {
            get
            {
                return _raid;
            }
            private set
            {
                _raid = value;
            }
        }

        public Player Player
        {
            get
            {
                return _player;
            }
            private set
            {
                _player = value;
            }
        }

        public Encounter Boss
        {
            get
            {
                return _boss;
            }
            set
            {
                _boss = value;
            }
        }

        public int DPS
        {
            get
            {
                return _dps;
            }
            set
            {
                _dps = value;
                CalculateVariance();
            }
        }

        public int MedianDPSForSpecAndEncounter
        {
            get
            {
                return _medianDPS;
            }
            set
            {
                _medianDPS = value;
                CalculateVariance();
            }
        }

        public double DifferenceAsAPercentageOfMedian
        {
            get
            {
                return _difference;
            }
            private set
            {
                _difference = value;
            }
        }

        public int PerformanceEntryId
        {
            get { return _performanceEntryId; }
            private set { _performanceEntryId = value; }
        }

        #endregion

        public void SavePerformanceEntry()
        {
            Boss.PerformanceEntries.Add(this);
            Player.PerformanceEntries.Add(this);
            //save to Database
            //save performanceEntryId to variable.
        }

        private void CalculateVariance()
        {
            if (MedianDPSForSpecAndEncounter != 0)
            {
                DifferenceAsAPercentageOfMedian = ((double)DPS - (double)MedianDPSForSpecAndEncounter) / (double)MedianDPSForSpecAndEncounter;
            }
        }

        
    }
}
